package cc.vv.baselibrary.activity;

import android.content.Context;
import android.content.ContextWrapper;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.VideoView;

import cc.vv.baselibrary.R;
import cc.vv.baselibrary.bean.PublicViewHolder;
import cc.vv.baselibrary.fragment.BaseVideoPlayerFragment;
import cc.vv.baselibrary.util.LKLogUtil;

/**
 * 公共播放器界面
 * Created by sun.li on 2018/9/19.
 *
 * @author sun.li
 */

public class BaseVideoPlayerActivity extends BaseActivity {

    public static final String VideoPathLogo = "VideoPathLogo";

    private String videoPath = "";

    private LinearLayout rl_bvpa_left_layout;

    @Override
    protected int initLayoutRes() {
        return R.layout.activity_base_video_player;
    }

    @Override
    protected PublicViewHolder initViewHolderObject() {
        return null;
    }

    @Override
    protected void baseOnClick(int viewId) {

    }

    @Override
    protected void initView(@Nullable Bundle bundle) {
        super.initView(bundle);
        try {
            videoPath = getIntent().getStringExtra(VideoPathLogo);
        } catch (Exception e) {
            e.printStackTrace();
            videoPath = "";
        }
        rl_bvpa_left_layout = findViewById(R.id.rl_bvpa_left_layout);
        rl_bvpa_left_layout.bringToFront();
        rl_bvpa_left_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        try {
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction transaction = fragmentManager.beginTransaction();
            BaseVideoPlayerFragment newsListFragment = new BaseVideoPlayerFragment();
            transaction.add(R.id.fl_bvpa_content_layout, newsListFragment);
            transaction.commit();
        } catch (Exception e) {
            LKLogUtil.e(e.toString(),e);
        }
    }



    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            System.gc();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(new ContextWrapper(newBase));
    }

    @Override
    public Object getSystemService(@NonNull String name) {
        if (Context.AUDIO_SERVICE.equals(name)) {
            return getApplicationContext().getSystemService(name);
        }
        return super.getSystemService(name);
    }
}
